package com.bw.video_module.video.adapter;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import com.bw.adapter_sdk.quick.BaseQuickMoreAdapter;
import com.bw.adapter_sdk.quick.BaseViewHolder;
import com.bw.ijk.widget.VideoView;
import com.bw.network_sdk.videoentity.VideoValuesEntity;
import com.bw.video_module.R;

public class VideoAdapter extends BaseQuickMoreAdapter<VideoValuesEntity> {

    @Override
    public void convert(BaseViewHolder holder, VideoValuesEntity item) {
        if (item.itemType == 0){
            holder.setText(R.id.item_content_artist,item.author.name);
            holder.setText(R.id.item_content_content,item.feeds_text);
            holder.setText(R.id.item_content_likes_count,item.ugc.likeCount+"");
            holder.setText(R.id.item_content_share_count,item.ugc.shareCount+"");
            holder.setText(R.id.item_content_comment_count,item.ugc.commentCount+"");

            holder.setCirImage(R.id.item_content_artist_img,item.author.avatar);

            ImageView image_like = holder.getView(R.id.item_content_likes_img);
            ImageView image_diss = holder.getView(R.id.item_content_unlikes_img);

            if (item.ugc.hasLiked)
                image_like.setImageResource(R.drawable.icon_cell_liked);
            else
                image_like.setImageResource(R.drawable.icon_cell_like);

            if (item.ugc.hasdiss)
                image_diss.setImageResource(R.drawable.icon_cell_dissed);
            else
                image_diss.setImageResource(R.drawable.icon_cell_diss);
        }else if (item.itemType == 1){
            holder.setText(R.id.item_picture_artist,item.author.name);
            holder.setText(R.id.item_picture_content,item.feeds_text);
            holder.setText(R.id.item_picture_likes_count,item.ugc.likeCount+"");
            holder.setText(R.id.item_picture_share_count,item.ugc.shareCount+"");
            holder.setText(R.id.item_picture_comment_count,item.ugc.commentCount+"");

            holder.setCirImage(R.id.item_picture_artist_img,item.author.avatar);
            holder.setImage(R.id.item_picture_bigimg,item.cover);

            ImageView image_like = holder.getView(R.id.item_picture_likes_img);
            ImageView image_diss = holder.getView(R.id.item_picture_unlikes_img);

            if (item.ugc.hasLiked)
                image_like.setImageResource(R.drawable.icon_cell_liked);
            else
                image_like.setImageResource(R.drawable.icon_cell_like);

            if (item.ugc.hasdiss)
                image_diss.setImageResource(R.drawable.icon_cell_dissed);
            else
                image_diss.setImageResource(R.drawable.icon_cell_diss);
        }else if (item.itemType == 2){
            holder.setText(R.id.item_video_artist,item.author.name);
            holder.setText(R.id.item_video_content,item.feeds_text);
            holder.setText(R.id.item_video_likes_count,item.ugc.likeCount+"");
            holder.setText(R.id.item_video_share_count,item.ugc.shareCount+"");
            holder.setText(R.id.item_video_comment_count,item.ugc.commentCount+"");

            holder.setCirImage(R.id.item_video_artist_img,item.author.avatar);

            VideoView videoView = holder.getView(R.id.item_video_ijkview);
            videoView.setPlayUrl(item.url,item.cover);
            videoView.start();


            ImageView image_like = holder.getView(R.id.item_video_likes_img);
            ImageView image_diss = holder.getView(R.id.item_video_unlikes_img);

            if (item.ugc.hasLiked)
                image_like.setImageResource(R.drawable.icon_cell_liked);
            else
                image_like.setImageResource(R.drawable.icon_cell_like);

            if (item.ugc.hasdiss)
                image_diss.setImageResource(R.drawable.icon_cell_dissed);
            else
                image_diss.setImageResource(R.drawable.icon_cell_diss);
        }
    }

    @Override
    protected View createItemView(int viewType) {
        if (viewType == 0){
            View contentView = LayoutInflater.from(context).inflate(R.layout.item_content,null,false);
            return contentView;
        }else if (viewType == 1){
            View pictureView = LayoutInflater.from(context).inflate(R.layout.item_picture,null,false);
            return pictureView;
        } else if ((viewType == 2)) {
            View videoView = LayoutInflater.from(context).inflate(R.layout.item_video,null,false);
            return videoView;
        }
        return null;
    }

    @Override
    public int getItemTtype(int position) {
        return getData().get(position).itemType;
    }
}
